package cn.jee.repositories;

import cn.jee.dto.Stu2AgeDto;
import cn.jee.dto.Stu2NameRecord;
import cn.jee.entity.Stu2;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;


import java.util.List;

@Repository
public interface Stu2Repository extends JpaRepository<Stu2,Long> {
  //不分大小写按姓名模糊查询
  List<Stu2> findAllByNameContainsIgnoreCase(String name);
  //分页
  Page<Stu2> findAllByNameContainsIgnoreCase(String name, Pageable pageable);
  //name模糊查询，age是一个范围，age的降序，id的升序
  List<Stu2> searchAllByNameContainsAndAgeBetweenOrderByAgeDescIdAsc(String name ,int min,int max);
  @Query("from Stu2 where age>:age")
  List<Stu2> find2(int age);

  List<Stu2> findByNameContainsIgnoreCaseAndAgeBetweenOrderByAgeDescNameAsc(String name, int ageStart, int ageEnd);

  @Query("select new cn.jee.dto.Stu2AgeDto(age) from Stu2")
  List<Stu2AgeDto> dto();
  @Query("select new cn.jee.dto.Stu2NameRecord(name) from Stu2")
  List<Stu2NameRecord> record();
}
